// Sample for SharpPlot
// Compile using "csc /r:SharpPlot.dll sample.cs"

using System;
using System.Drawing;
using System.Drawing.Imaging;
using Causeway;

namespace SharpPlotSample
{
  class Example
  {
    static void Main(string[] args)
    {
      // A simple composite chart showing most key features
      // Overlays a linechart on a barchart and adds a small piechart in the corner
      SharpPlot sp = new SharpPlot();
      sp.Heading = "Financial Summary for Current Year";
      sp.SetHeadingFont("Arial",18,FontStyle.Bold,Color.Firebrick);
	  
      int[] data1 = new int[] {6,18,27,31,56,72,45,12};
      int[] data2 = new int[] {9,23,32,33,59,81,47,13};
      int[] xdata = new int[] {126,128,129,130,131,135,137,18};
      string[] xlabs = new string[]{"Jan","Feb","Mar","Apr","May","June","July","August\n(part)"};
	  
      // Start with a nice graded paper
      sp.SetBackground(Color.Wheat,FillStyle.GradientBottomRight);
      sp.MarginTop = 56;
      
	  // Check out a custom line-style for the datum line
      sp.SetDatumLineStyle(Color.Navy,new LineStyle(new int[] {24,3,2,3,2,3}));
      sp.SetYDatumLines(40);
      
	  // Draw the base barchart
      sp.YCaption = "$M";
      sp.YAxisStyle = YAxisStyles.ForceZero|YAxisStyles.AtEndCaption;
      sp.SetXLabels(xlabs);
      sp.DrawBarChart(data1);
      
	  // Overlay a linegraph on the same axis set
      sp.LineGraphStyle = LineGraphStyles.Markers|LineGraphStyles.Risers|LineGraphStyles.Curves;
      sp.SetLineStyles(LineStyle.Dash);
      sp.SetMarkers(Marker.Lozenge);
      sp.SetColors(new Color[]{Color.DodgerBlue,Color.Firebrick,Color.Firebrick});
      sp.SetPenWidths(0.8);  // For line and risers
      sp.Flexibility = 5;
      sp.DrawLineGraph(data2);
      
	  // Key picks up series info from both charts
      sp.SetKeyText(new string[]{"Revenue","Invoiced Sales"});
      sp.KeyStyle = KeyStyles.Boxed|KeyStyles.Rounded;
      
	  // Add some free text in a box
      sp.NoteStyle = NoteStyles.Boxed|NoteStyles.Rounded;
      sp.SetNoteBackground(Color.Goldenrod);
      sp.SetNoteFont(Color.White);
      sp.DrawNote("Note: April figures were affected by warehouse fire.",3.5,20,0,1.6);
      
	  // Finally, drop in a small pie (scaled to 50% and off-centre)
      sp.SetXLabelFont("Arial",13.4,FontStyle.Bold,Color.Navy);
      sp.SetXLabels(new string[]{"Home","Export"});
      sp.SetPieCenter(100,180);
      sp.PieRadius = 50;
      sp.SetEdgeStyle(Color.White,LineStyle.Solid,1.8);
      sp.DrawPieChart(new int[] {34,23});
      
	  // Save the chart as an SVG image (in the current directory)
      string filename = "sample";
      sp.SaveSvg(filename + ".svg");
      
	  // Save the chart as a 96dpi PNG image
      sp.SaveImage(filename + ".png", ImageFormat.Png);
      Console.WriteLine("Saved " + filename + " as an SVG image, and a small PNG image");
    }
  }
}
